package db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DB implements IDB {
    Connection conn=null;
    @Override
    public Connection getConn() throws SQLException {

        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/shop?useUnicode=true&characterEncoding=utf-8","root","root");
        return conn;
    }

    @Override
    public void closeConn() throws SQLException {
        if(conn!=null&&!conn.isClosed()){
            conn.close();
        }

    }

    public static void main(String[] args){
        DB db=new DB();
        try {
            System.out.print(db.getConn().isClosed());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
